
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>八、STL · 计算机笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="海拉尔的三角">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro-fixed/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-ancre-navigation/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-insert-logo-link-website/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-lightbox/css/lightbox.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-pageview-count/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-auto-scroll-table/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-katex-pro/katex.min.css">
                
            
                
                <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-sectionx/sectionx.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-terminull-light/terminull.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="dataStruction_withNum.html" />
    
    
    <link rel="prev" href="locks_withNum.html" />
    

    
        <link rel="shortcut icon" href="image/ico.png" type="image/x-icon">
    
    
    
    
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="image/ico.png">
    
    
        
    
    
        
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://github.com/spite-triangle" target="_blank" class="custom-link">Github</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../cpp.html">
            
                <a href="../cpp.html">
            
                    
                    C/C++
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="foundation_withNum.html">
            
                <a href="foundation_withNum.html">
            
                    
                    一、基础概念
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="keyword_withNum.html">
            
                <a href="keyword_withNum.html">
            
                    
                    二、关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="point_reference_withNum.html">
            
                <a href="point_reference_withNum.html">
            
                    
                    三、指针与引用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="oop_withNum.html">
            
                <a href="oop_withNum.html">
            
                    
                    四、面向对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.5" data-path="memory_withNum.html">
            
                <a href="memory_withNum.html">
            
                    
                    五、内存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.6" data-path="process_withNum.html">
            
                <a href="process_withNum.html">
            
                    
                    六、进程与线程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.7" data-path="locks_withNum.html">
            
                <a href="locks_withNum.html">
            
                    
                    七、锁
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.1.8" data-path="stl_withNum.html">
            
                <a href="stl_withNum.html">
            
                    
                    八、STL
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.9" data-path="dataStruction_withNum.html">
            
                <a href="dataStruction_withNum.html">
            
                    
                    九、数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.10" data-path="array_list_withNum.html">
            
                <a href="array_list_withNum.html">
            
                    
                    十、数组链表操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.11" data-path="find_withNum.html">
            
                <a href="find_withNum.html">
            
                    
                    十一、目标查找
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.12" data-path="tree_withNum.html">
            
                <a href="tree_withNum.html">
            
                    
                    十二、树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.13" data-path="binaryTree_withNum.html">
            
                <a href="binaryTree_withNum.html">
            
                    
                    十三、二叉树
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.14" data-path="dynamicProgram_withNum.html">
            
                <a href="dynamicProgram_withNum.html">
            
                    
                    十四、动态规划
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.15" data-path="backtracking_withNum.html">
            
                <a href="backtracking_withNum.html">
            
                    
                    十五、回溯算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.16" data-path="monotoneStack_withNum.html">
            
                <a href="monotoneStack_withNum.html">
            
                    
                    十六、单调栈
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.17" data-path="toollib_withNum.html">
            
                <a href="toollib_withNum.html">
            
                    
                    附录 工具库
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../../MySQL/mysql.html">
            
                <a href="../../MySQL/mysql.html">
            
                    
                    MySQL
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../../MySQL/chapter/introduction_withNum.html">
            
                <a href="../../MySQL/chapter/introduction_withNum.html">
            
                    
                    一、简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../../MySQL/chapter/foundation_withNum.html">
            
                <a href="../../MySQL/chapter/foundation_withNum.html">
            
                    
                    二、控制台操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="../../MySQL/chapter/operatorDB_withNum.html">
            
                <a href="../../MySQL/chapter/operatorDB_withNum.html">
            
                    
                    三、数据库、表操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" data-path="../../MySQL/chapter/operatorData_withNum.html">
            
                <a href="../../MySQL/chapter/operatorData_withNum.html">
            
                    
                    四、数据操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.5" data-path="../../MySQL/chapter/transaction_withNum.html">
            
                <a href="../../MySQL/chapter/transaction_withNum.html">
            
                    
                    五、事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.6" data-path="../../MySQL/chapter/index_withNum.html">
            
                <a href="../../MySQL/chapter/index_withNum.html">
            
                    
                    六、索引
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.7" data-path="../../MySQL/chapter/authority_withNum.html">
            
                <a href="../../MySQL/chapter/authority_withNum.html">
            
                    
                    七、权限管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.8" data-path="../../MySQL/chapter/backup_withNum.html">
            
                <a href="../../MySQL/chapter/backup_withNum.html">
            
                    
                    八、备份
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../../linux/linux.html">
            
                <a href="../../linux/linux.html">
            
                    
                    Linux
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../../linux/chapter/foundation_withNum.html">
            
                <a href="../../linux/chapter/foundation_withNum.html">
            
                    
                    一、原理知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../../linux/chapter/command_withNum.html">
            
                <a href="../../linux/chapter/command_withNum.html">
            
                    
                    二、指令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="5.1" data-path="../../tcp_udp/tcp_upd.html">
            
                <a href="../../tcp_udp/tcp_upd.html">
            
                    
                    网络
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.1" data-path="../../tcp_udp/chapter/foundation_withNum.html">
            
                <a href="../../tcp_udp/chapter/foundation_withNum.html">
            
                    
                    一、网络通讯基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="5.1.2" data-path="../../tcp_udp/chapter/tcp_udp_withNum.html">
            
                <a href="../../tcp_udp/chapter/tcp_udp_withNum.html">
            
                    
                    二、tcp/udp
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >八、STL</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-anchor"></i><ul><li><span class="title-icon "></span><a href="#stl"><b></b>STL</a></li><li><span class="title-icon "></span><a href="#1-&#x7B80;&#x4ECB;"><b></b>1. &#x7B80;&#x4ECB;</a></li><li><span class="title-icon "></span><a href="#2-&#x5BB9;&#x5668;&#xFF08;container&#xFF09;"><b></b>2. &#x5BB9;&#x5668;&#xFF08;Container&#xFF09;</a></li><li><span class="title-icon "></span><a href="#3-&#x5206;&#x914D;&#x5668;"><b></b>3. &#x5206;&#x914D;&#x5668;</a></li><li><span class="title-icon "></span><a href="#4-&#x8FED;&#x4EE3;&#x5668;"><b></b>4. &#x8FED;&#x4EE3;&#x5668;</a></li><li><span class="title-icon "></span><a href="#5-&#x7B97;&#x6CD5;"><b></b>5. &#x7B97;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#6-&#x4EFF;&#x51FD;&#x6570;"><b></b>6. &#x4EFF;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#7-&#x5BB9;&#x5668;&#x9002;&#x914D;&#x5668;"><b></b>7. &#x5BB9;&#x5668;&#x9002;&#x914D;&#x5668;</a></li></ul></div><a href="#stl" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 style="font-size:60px;text-align:center;" id="stl"><a name="stl" class="anchor-navigation-ex-anchor" href="#stl"><i class="fa fa-link" aria-hidden="true"></i></a>STL</h1>

<h1 id="1-&#x7B80;&#x4ECB;"><a name="1-&#x7B80;&#x4ECB;" class="anchor-navigation-ex-anchor" href="#1-&#x7B80;&#x4ECB;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x7B80;&#x4ECB;</h1>
<p>&#x2003;&#x2003;STL&#xFF08;Standard Template Library&#xFF09;&#xFF0C;&#x5373;&#x6807;&#x51C6;&#x6A21;&#x677F;&#x5E93;&#xFF0C;&#x662F;&#x4E00;&#x4E2A;&#x5177;&#x6709;&#x5DE5;&#x4E1A;&#x5F3A;&#x5EA6;&#x7684;&#xFF0C;&#x9AD8;&#x6548;&#x7684;C++&#x7A0B;&#x5E8F;&#x5E93;&#x3002;&#x8BE5;&#x5E93;&#x5305;&#x542B;&#x4E86;&#x8BF8;&#x591A;&#x5728;&#x8BA1;&#x7B97;&#x673A;&#x79D1;&#x5B66;&#x9886;&#x57DF;&#x91CC;&#x6240;&#x5E38;&#x7528;&#x7684;<strong>&#x57FA;&#x672C;&#x6570;&#x636E;&#x7ED3;&#x6784;</strong>&#x548C;<strong>&#x57FA;&#x672C;&#x7B97;&#x6CD5;</strong>&#x3002;</p>
<ul>
<li>&#x6570;&#x636E;&#x7ED3;&#x6784;&#x548C;&#x7B97;&#x6CD5;&#x7684;&#x5206;&#x79BB;</li>
<li>&#x4E0D;&#x662F;&#x9762;&#x5411;&#x5BF9;&#x8C61;&#x7684;</li>
<li><span style="color:red;font-weight:bold"> <code>STL</code>&#x5E93;&#x7684;&#x5B9E;&#x73B0;&#x5305;&#x542B;&#x4E86;&#x300C;&#x6CDB;&#x578B;&#x51FD;&#x6570;&#x300D;&#x548C; &#x300C;&#x6CDB;&#x578B;&#x7C7B;&#x300D;&#xFF1B; <code>STL</code>&#x7B97;&#x6CD5;&#x7684;&#x5B9E;&#x73B0;&#x53EA;&#x5305;&#x542B;&#x4E86;&#x300C;&#x6CDB;&#x578B;&#x51FD;&#x6570;&#x300D;</span></li>
</ul>
<p>&#x4E3B;&#x8981;&#x6784;&#x6210;&#x6709;&#x516D;&#x5927;&#x7EC4;&#x4EF6;:</p>
<ul>
<li>&#x5BB9;&#x5668;&#xFF08;Container&#xFF09;</li>
<li>&#x8FED;&#x4EE3;&#x5668;&#xFF08;Iterator&#xFF09;</li>
<li>&#x7B97;&#x6CD5;&#xFF08;Algorithm&#xFF09;</li>
<li>&#x4EFF;&#x51FD;&#x6570;&#xFF08;Functor&#xFF09;</li>
<li>&#x9002;&#x914D;&#x5668;&#xFF08;Adaptor&#xFF09;</li>
<li>&#x5206;&#x914D;&#x5668;&#xFF08;allocator&#xFF09;</li>
</ul>
<h1 id="2-&#x5BB9;&#x5668;&#xFF08;container&#xFF09;"><a name="2-&#x5BB9;&#x5668;&#xFF08;container&#xFF09;" class="anchor-navigation-ex-anchor" href="#2-&#x5BB9;&#x5668;&#xFF08;container&#xFF09;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x5BB9;&#x5668;&#xFF08;Container&#xFF09;</h1>
<ul>
<li><strong>&#x5E8F;&#x5217;&#x5F0F;&#x5BB9;&#x5668;</strong>&#xFF08;Sequence containers&#xFF09;<ul>
<li>Vector: &#x52A8;&#x6001;&#x6570;&#x7EC4;</li>
<li>Deque: &#x53CC;&#x7AEF;&#x961F;&#x5217;&#xFF0C;&#x662F;&#x4E00;&#x79CD;&#x5177;&#x6709;<strong>&#x961F;&#x5217;&#x548C;&#x6808;</strong>&#x7684;&#x6027;&#x8D28;&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x3002;&#x5143;&#x7D20;&#x53EF;&#x4EE5;&#x4ECE;&#x4E24;&#x7AEF;&#x5F39;&#x51FA;&#xFF0C;<strong>&#x5176;&#x9650;&#x5B9A;&#x63D2;&#x5165;&#x548C;&#x5220;&#x9664;&#x64CD;&#x4F5C;&#x5728;&#x8868;&#x7684;&#x4E24;&#x7AEF;&#x8FDB;&#x884C;</strong>&#x3002;</li>
<li>List: &#x53CC;&#x5411;&#x94FE;&#x8868;</li>
</ul>
</li>
<li><strong>&#x5173;&#x8054;&#x5F0F;&#x5BB9;&#x5668;</strong>&#xFF08;Associated containers)<ul>
<li>Set/Multiset: Set&#x5185;&#x7684;&#x76F8;&#x540C;&#x6570;&#x503C;&#x7684;&#x5143;&#x7D20;&#x53EA;&#x80FD;&#x51FA;&#x73B0;&#x4E00;&#x6B21;; Multisets&#x5185;&#x53EF;&#x5305;&#x542B;&#x591A;&#x4E2A;&#x6570;&#x503C;&#x76F8;&#x540C;&#x7684;&#x5143;&#x7D20;&#x3002;</li>
<li>Map/Multimap: map&#x53EA;&#x5141;&#x8BB8;key&#x552F;&#x4E00;&#xFF1B;multimap&#x4E2D;key&#x53EF;&#x4EE5;&#x91CD;&#x590D;&#x4F7F;&#x7528;&#xFF1B;</li>
</ul>
</li>
</ul>
<blockquote>
<p>[!note|style:flat]
<code>set map multiset multimap</code> &#x901A;&#x8FC7;&#x7EA2;&#x9ED1;&#x5B9E;&#x73B0;&#xFF0C;&#x65E0;&#x5E8F; <code>unorder_map unorder_set</code> &#x901A;&#x8FC7;&#x54C8;&#x5E0C;&#x8868;&#x5B9E;&#x73B0;&#x3002;</p>
</blockquote>
<h1 id="3-&#x5206;&#x914D;&#x5668;"><a name="3-&#x5206;&#x914D;&#x5668;" class="anchor-navigation-ex-anchor" href="#3-&#x5206;&#x914D;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x5206;&#x914D;&#x5668;</h1>
<font color="#f44336">&#x5BB9;&#x5668;&#x7C7B;&#x81EA;&#x52A8;&#x7533;&#x8BF7;&#x548C;&#x91CA;&#x653E;&#x5185;&#x5B58;&#xFF0C;&#x65E0;&#x9700;new&#x548C;delete&#x64CD;&#x4F5C;&#x3002;</font>

<h1 id="4-&#x8FED;&#x4EE3;&#x5668;"><a name="4-&#x8FED;&#x4EE3;&#x5668;" class="anchor-navigation-ex-anchor" href="#4-&#x8FED;&#x4EE3;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>4. &#x8FED;&#x4EE3;&#x5668;</h1>
<ul>
<li>&#x904D;&#x5386;&#x6570;&#x636E;&#x7528;&#x7684;&#x3002;</li>
<li><font color="#f44336">&#x652F;&#x6301;&#x8FD0;&#x7B97;&#x7B26;:  <code>*;+&#xFF0B;;&#xFF1D;&#xFF1D;;&#xFF01;&#xFF1D;;&#xFF1D;</code> </font>&#x3002;</li>
<li><font color="#f44336"> &#x6307;&#x9488;&#x64CD;&#x4F5C; </font>

</li>
</ul>
<pre class="language-"><code class="lang-cpp">Container c<span class="token punctuation">;</span>
    Container<span class="token double-colon punctuation">::</span>iterator it<span class="token punctuation">;</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span>it<span class="token operator">=</span>c<span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>it<span class="token operator">!=</span>c<span class="token punctuation">.</span><span class="token function">end</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>it<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment">// vector &#x83B7;&#x53D6;&#x503C;</span>
        <span class="token operator">*</span>it<span class="token punctuation">;</span>
        <span class="token comment">// map &#x83B7;&#x53D6;&#x952E;&#x503C;&#x5BF9;</span>
        it<span class="token operator">-&gt;</span>first<span class="token punctuation">;</span>
        it<span class="token operator">-&gt;</span>second<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre>
<ul>
<li><span style="color:red;font-weight:bold"> &#x5E26;&#x8FED;&#x4EE3;&#x5668;&#x7684;&#x5BB9;&#x5668;&#x904D;&#x5386; </span></li>
</ul>
<pre class="language-"><code class="lang-cpp"><span class="token comment">// &#x53EA;&#x8BFB;</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">auto</span> item<span class="token operator">:</span>containers<span class="token punctuation">)</span><span class="token punctuation">{</span>

    <span class="token punctuation">}</span>
    <span class="token comment">// &#x53EF;&#x4FEE;&#x6539; &#x80FD;&#x4FEE;&#x6539;&#x7684;&#x503C;</span>
    <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">auto</span><span class="token operator">&amp;</span> item<span class="token operator">:</span>containers<span class="token punctuation">)</span><span class="token punctuation">{</span>

    <span class="token punctuation">}</span>
</code></pre>
<h1 id="5-&#x7B97;&#x6CD5;"><a name="5-&#x7B97;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#5-&#x7B97;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>5. &#x7B97;&#x6CD5;</h1>
<h3 id="51-&#x5934;&#x6587;&#x4EF6;"><a name="51-&#x5934;&#x6587;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#51-&#x5934;&#x6587;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>5.1. &#x5934;&#x6587;&#x4EF6;</h3>
<p>&#x2003;&#x2003;&#x7B97;&#x6CD5;&#x90E8;&#x5206;&#x4E3B;&#x8981;&#x7531;&#x5934;&#x6587;&#x4EF6;<code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>algorithm</span><span class="token punctuation">&gt;</span></span></code>&#xFF0C;<numeric>&#x548C;<functional>&#x7EC4;&#x6210;&#x3002;</functional></numeric></p>
<ul>
<li><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>algorithm</span><span class="token punctuation">&gt;</span></span></code>: &#x7531;&#x4E00;&#x5927;&#x5806;&#x6A21;&#x7248;&#x51FD;&#x6570;&#x7EC4;&#x6210;&#x7684;&#xFF0C;&#x53EF;&#x4EE5;&#x8BA4;&#x4E3A;&#x6BCF;&#x4E2A;&#x51FD;&#x6570;&#x5728;&#x5F88;&#x5927;&#x7A0B;&#x5EA6;&#x4E0A;&#x90FD;&#x662F;&#x72EC;&#x7ACB;&#x7684;&#xFF0C;&#x5176;&#x4E2D;&#x5E38;&#x7528;&#x5230;&#x7684;&#x529F;&#x80FD;&#x8303;&#x56F4;&#x6D89;&#x53CA;&#x5230;&#x6BD4;&#x8F83;&#x3001;&#x4EA4;&#x6362;&#x3001;&#x67E5;&#x627E;&#x3001;&#x904D;&#x5386;&#x64CD;&#x4F5C;&#x3001;&#x590D;&#x5236;&#x3001;&#x4FEE;&#x6539;&#x3001;&#x79FB;&#x9664;&#x3001;&#x53CD;&#x8F6C;&#x3001;&#x6392;&#x5E8F;&#x3001;&#x5408;&#x5E76;&#x7B49;&#x7B49;&#x3002;</li>
<li><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>numeric</span><span class="token punctuation">&gt;</span></span></code>: &#x53EA;&#x5305;&#x62EC;&#x51E0;&#x4E2A;&#x5728;&#x5E8F;&#x5217;&#x4E0A;&#x9762;&#x8FDB;&#x884C;&#x7B80;&#x5355;&#x6570;&#x5B66;&#x8FD0;&#x7B97;&#x7684;&#x6A21;&#x677F;&#x51FD;&#x6570;&#xFF0C;&#x5305;&#x62EC;&#x52A0;&#x6CD5;&#x548C;&#x4E58;&#x6CD5;&#x5728;&#x5E8F;&#x5217;&#x4E0A;&#x7684;&#x4E00;&#x4E9B;&#x64CD;&#x4F5C;&#x3002;</li>
<li><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>functional</span><span class="token punctuation">&gt;</span></span></code>: &#x4E2D;&#x5219;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E9B;&#x6A21;&#x677F;&#x7C7B;&#xFF0C;&#x7528;&#x4EE5;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x5BF9;&#x8C61;&#x3002;</li>
</ul>
<h3 id="52-&#x5E38;&#x7528;&#x7B97;&#x6CD5;"><a name="52-&#x5E38;&#x7528;&#x7B97;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#52-&#x5E38;&#x7528;&#x7B97;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>5.2. &#x5E38;&#x7528;&#x7B97;&#x6CD5;</h3>
<p>&#x2003;&#x2003; <a href="https://blog.csdn.net/b_ingram/article/details/118874862" target="_blank">STL&#x5E38;&#x7528;&#x7B97;&#x6CD5;</a></p>
<h1 id="6-&#x4EFF;&#x51FD;&#x6570;"><a name="6-&#x4EFF;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#6-&#x4EFF;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>6. &#x4EFF;&#x51FD;&#x6570;</h1>
<p>&#x2003;&#x2003; <strong>&#x94A9;&#x5B50;&#x51FD;&#x6570;&#xFF0C;&#x53EF;&#x4EE5;&#x5F53;&#x53C2;&#x6570;&#x4F20;&#x9012;&#xFF0C;&#x8BA9;&#x5177;&#x4F53;&#x7B97;&#x6CD5;&#x8FDB;&#x884C;&#x8C03;&#x7528;&#x3002;</strong> &#x7CFB;&#x7EDF;&#x5B9A;&#x4E49;&#x597D;&#x7684;&#x4EFF;&#x51FD;&#x6570;: <code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>functional\</span><span class="token punctuation">&gt;</span></span></code></p>
<ul>
<li>&#x51FD;&#x6570;&#x6307;&#x9488;&#x5B9E;&#x73B0;</li>
<li>&#x4EFF;&#x51FD;&#x6570;&#x5B9E;&#x73B0;:<ol>
<li>&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;<strong>&#x7B80;&#x5355;&#x7684;&#x7C7B;</strong></li>
<li>&#x5B9E;&#x73B0; <code>operator()</code> &#x64CD;&#x4F5C;&#x7B26;&#xFF0C;<strong>&#x672C;&#x8D28;&#x4E0A;&#x5C31;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x7B26;&#x53F7;&#x51FD;&#x6570;</strong>&#x3002;</li>
</ol>
</li>
</ul>
<pre class="language-"><code class="lang-cpp"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span></span>
    <span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;algorithm&gt;</span></span>
    <span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;vector&gt;</span></span>

    <span class="token keyword">class</span> <span class="token class-name">Compare</span><span class="token punctuation">{</span>
        <span class="token keyword">public</span><span class="token operator">:</span>
        <span class="token keyword">bool</span> <span class="token keyword">operator</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token keyword">int</span> a<span class="token punctuation">,</span><span class="token keyword">int</span> b<span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">return</span> a <span class="token operator">&gt;</span> b<span class="token punctuation">;</span>
        <span class="token punctuation">}</span> 
    <span class="token punctuation">}</span><span class="token punctuation">;</span>

    <span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">int</span> argn<span class="token punctuation">,</span><span class="token keyword">const</span> <span class="token keyword">char</span><span class="token operator">*</span> args<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        vector<span class="token operator">&lt;</span><span class="token keyword">int</span><span class="token operator">&gt;</span> <span class="token function">vec</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        vec<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span>
        vec<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
        vec<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">9</span><span class="token punctuation">;</span>
        vec<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">;</span>
        vec<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>

        <span class="token comment">// &#x6392;&#x5E8F;&#x7B97;&#x6CD5;</span>
        <span class="token function">sort</span><span class="token punctuation">(</span>vec<span class="token punctuation">.</span><span class="token function">begin</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>vec<span class="token punctuation">.</span><span class="token function">end</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token function">Compare</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token comment">// &#x5B9E;&#x9645;&#x7684;&#x51FD;&#x6570;&#x8C03;&#x7528;</span>
        <span class="token keyword">bool</span> flag <span class="token operator">=</span> <span class="token function">Compare</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span><span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token punctuation">}</span>
</code></pre>
<blockquote>
<p>[!note|style:flat]
<strong>&#x6CE8;&#x610F;&#xFF1A;</strong>
<strong><code>Compare()</code>&#x662F;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x4E34;&#x65F6;&#x5BF9;&#x8C61;</strong>&#xFF0C;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x9012;&#x7ED9;&#x4E86; <code>sort()</code>&#xFF1B;<strong>&#x82E5;<code>sort()</code>&#x6CA1;&#x6709;&#x91C7;&#x7528;&#x5F15;&#x7528;&#x4F20;&#x9012;&#xFF0C;&#x5219;&#x5BF9;&#x8C61;&#x5C06;&#x662F;&#x503C;&#x4F20;&#x9012;&#x3002;</strong></p>
</blockquote>
<h1 id="7-&#x5BB9;&#x5668;&#x9002;&#x914D;&#x5668;"><a name="7-&#x5BB9;&#x5668;&#x9002;&#x914D;&#x5668;" class="anchor-navigation-ex-anchor" href="#7-&#x5BB9;&#x5668;&#x9002;&#x914D;&#x5668;"><i class="fa fa-link" aria-hidden="true"></i></a>7. &#x5BB9;&#x5668;&#x9002;&#x914D;&#x5668;</h1>
<p>&#x2003;&#x2003;&#x5BF9;&#x57FA;&#x7840;&#x5BB9;&#x5668;&#x8FDB;&#x884C;&#x529F;&#x80FD;&#x6269;&#x5C55;&#xFF0C;&#x6807;&#x51C6;&#x5E93;&#x63D0;&#x4F9B;&#x4E86;&#x4E09;&#x79CD;&#x987A;&#x5E8F;&#x5BB9;&#x5668;&#x9002;&#x914D;&#x5668;:</p>
<ul>
<li><strong>queue</strong>(FIFO&#x961F;&#x5217;)</li>
<li><strong>stack</strong>(&#x6808;)</li>
<li><strong>priority_queue</strong>(&#x4F18;&#x5148;&#x7EA7;&#x961F;&#x5217;)</li>
</ul>
<table>
<thead>
<tr>
<th>&#x5BB9;&#x5668;</th>
<th>&#x5934;&#x6587;&#x4EF6;</th>
<th>&#x9ED8;&#x8BA4;&#x5BB9;&#x5668;</th>
<th>&#x53EF;&#x9009;&#x5BB9;&#x5668;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>queue</td>
<td><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>queue</span><span class="token punctuation">&gt;</span></span></code></td>
<td>deque</td>
<td>list&#x3001;deque</td>
<td>&#x57FA;&#x7840;&#x5BB9;&#x5668;&#x5FC5;&#x987B;&#x63D0;&#x4F9B;push_front()&#x8FD0;&#x7B97;</td>
</tr>
<tr>
<td>priority_queue</td>
<td><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>queue</span><span class="token punctuation">&gt;</span></span></code></td>
<td>vector</td>
<td>vector&#x3001;deque</td>
<td>&#x57FA;&#x7840;&#x5BB9;&#x5668;&#x5FC5;&#x987B;&#x63D0;&#x4F9B;&#x968F;&#x673A;&#x8BBF;&#x95EE;&#x529F;&#x80FD;</td>
</tr>
<tr>
<td>stack</td>
<td><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>stack</span><span class="token punctuation">&gt;</span></span></code></td>
<td>deque</td>
<td>vector&#x3001;list&#x3001;deque</td>
</tr>
</tbody>
</table>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="locks_withNum.html" class="navigation navigation-prev " aria-label="Previous page: 七、锁">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="dataStruction_withNum.html" class="navigation navigation-next " aria-label="Next page: 九、数据结构">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"八、STL","level":"2.1.8","depth":2,"next":{"title":"九、数据结构","level":"2.1.9","depth":2,"path":"cpp/chapter/dataStruction_withNum.md","ref":"cpp/chapter/dataStruction_withNum.md","articles":[]},"previous":{"title":"七、锁","level":"2.1.7","depth":2,"path":"cpp/chapter/locks_withNum.md","ref":"cpp/chapter/locks_withNum.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-lunr","-search","search-pro-fixed","expandable-chapters-small","ancre-navigation","hide-element","code","splitter","insert-logo-link-website","-sharing","sharing-plus","prism","-highlight","flexible-alerts","lightbox","pageview-count","auto-scroll-table","katex-pro","favicon-absolute","sectionx","terminull-light","livereload"],"styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"prism":{"css":["prismjs/themes/prism-tomorrow.css"],"lang":{"flow":"typescript"}},"livereload":{},"splitter":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"auto-scroll-table":{},"code":{"copyButtons":true},"terminull-light":{},"search-pro-fixed":{},"favicon-absolute":{"favicon":"image/ico.png","appleTouchIconPrecomposed152":"image/ico.png","appleTouchIconMore":{},"appleTouchIconPrecomposedMore":{}},"hide-element":{"elements":[".gitbook-link"]},"katex-pro":{},"fontsettings":{"theme":"white","family":"sans","size":2},"sectionx":{"tag":"b"},"lightbox":{"jquery":true,"sameUuid":false},"insert-logo-link-website":{"url":"image/logo.png","link":"https://space.bilibili.com/27206875","target":"_blank","style":"height: 230px"},"pageview-count":{},"ancre-navigation":{"showLevel":true,"associatedWithSummary":true,"mode":"float","printLog":false,"multipleH1":true,"float":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""},"pageTop":{"showLevelIcon":false,"level1Icon":"","level2Icon":"","level3Icon":""}},"expandable-chapters-small":{},"flexible-alerts":{"style":"callout","note":{"label":"Note","icon":"fa fa-info-circle","className":"info"},"tip":{"label":"Tip","icon":"fa fa-lightbulb-o","className":"tip"},"warning":{"label":"Warning","icon":"fa fa-exclamation-triangle","className":"warning"},"danger":{"label":"Attention","icon":"fa fa-ban","className":"danger"}},"sharing":{"qq":true,"all":["douban","facebook","google","instapaper","linkedin","twitter","weibo","messenger","qq","qzone","viber","whatsapp"],"douban":false,"facebook":false,"weibo":true,"whatsapp":false,"twitter":false,"pocket":false,"google":true,"qzone":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"海拉尔的三角","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"计算机笔记","links":{"sidebar":{"Github":"https://github.com/spite-triangle"}},"gitbook":"*"},"file":{"path":"cpp/chapter/stl_withNum.md","mtime":"2021-09-14T15:43:12.915Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-09-14T15:43:23.052Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro-fixed/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro-fixed/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-insert-logo-link-website/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lightbox/js/lightbox.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-pageview-count/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-auto-scroll-table/plugin.js"></script>
        
    
        
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sectionx/sectionx.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-terminull-light/terminull.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

